﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using RayDen.Library.Core.Primitives;

namespace RayDen.Library.Core.Components
{
    public class Assert
    {

        public class AssertionException : ApplicationException
        {
            public AssertionException(string message) : base(message) { }
        }

        public static void IsNotNaN(float f, string s = null)
        {
               
            Eval(()=>!float.IsNaN(f), "Value is NaN " +s);
        }
        public static void IsNotNaN(ref Vector ft, string s = null)
        {
            var f = ft;
            Eval(() => !float.IsNaN(f.x), "Value is NaN " + s);
            Eval(() => !float.IsNaN(f.y), "Value is NaN " + s);
            Eval(() => !float.IsNaN(f.z), "Value is NaN " + s);

        }

        public static void Eval(Func<bool> eval, string message = null, bool throwException = true)
        {
            if (!eval())
            {
                if (!string.IsNullOrWhiteSpace(message))
                {
                    Console.WriteLine(message);
                }

                if (throwException)
                {
                    throw new AssertionException(message ?? "Assertion failed");
                }
                else
                {
                    Console.WriteLine("Assertion failed!");
                }
            }  
        }

        public static void IsTrue(bool expression, string message = null, bool throwException = true)
        {
            if (!expression)
            {
                if (!string.IsNullOrWhiteSpace(message))
                {
                    Console.WriteLine(message);
                }

                if (throwException)
                {
                    throw new AssertionException(message ?? "Assertion failed");
                }
                else
                {
                    Console.WriteLine("Assertion failed!");
                    Debugger.Break();
                }
            }
        }
    }
}
